#!/bin/bash

# When importing query results in parallel, you must specify --split-by.

start_time=`date +"%Y-%m-%d %H:%M:%S"`
echo "sqoop class_studying_student_count start ${start_time}" >> ./sqoop_liujie.log

/usr/bin/sqoop import "-Dorg.apache.sqoop.splitter.allow_text_splitter=true" \
--connect 'jdbc:mysql://192.168.88.80:3306/teach?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true' \
--username root \
--password 123456 \
--query "select id,school_id,subject_id,class_id,studying_student_count,studying_date \
 from class_studying_student_count where 1=1 and  \$CONDITIONS" \
--hcatalog-database edu_ods \
--hcatalog-table class_studying_student_count \
--split-by id \
-m 2

wait
start_time=`date +"%Y-%m-%d %H:%M:%S"`
echo ""
echo "sqoop class_studying_student_count end ${start_time}" >> ./sqoop_liujie.log
echo "sqoop course_table_upload_detail start ${start_time}" >> ./sqoop_liujie.log
echo ""

/usr/bin/sqoop import "-Dorg.apache.sqoop.splitter.allow_text_splitter=true" \
--connect 'jdbc:mysql://192.168.88.80:3306/teach?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true' \
--username root \
--password 123456 \
--query "select * from course_table_upload_detail where 1=1 and  \$CONDITIONS" \
--hcatalog-database edu_ods \
--hcatalog-table course_table_upload_detail \
--split-by id \
-m 2

wait
start_time=`date +"%Y-%m-%d %H:%M:%S"`
echo ""
echo "sqoop course_table_upload_detail end ${start_time}" >> ./sqoop_liujie.log
echo "sqoop student_leave_apply start ${start_time}" >> ./sqoop_liujie.log
echo ""


/usr/bin/sqoop import "-Dorg.apache.sqoop.splitter.allow_text_splitter=true" \
--connect 'jdbc:mysql://192.168.88.80:3306/teach?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true' \
--username root \
--password 123456 \
--query "select * from student_leave_apply where 1=1 and  \$CONDITIONS" \
--hcatalog-database edu_ods \
--hcatalog-table student_leave_apply \
--split-by id \
-m 2

wait
start_time=`date +"%Y-%m-%d %H:%M:%S"`
echo ""
echo "sqoop student_leave_apply end ${start_time}" >> ./sqoop_liujie.log
echo "sqoop tbh_class_time_table start ${start_time}" >> ./sqoop_liujie.log
echo ""

# Import failed: java.io.IOException: Caught Exception checking database column substr(create_time,1,10) in  hcatalog table.
# 说明：查询的字段要与hcatalog中的字段名一一对应
/usr/bin/sqoop import "-Dorg.apache.sqoop.splitter.allow_text_splitter=true" \
--connect 'jdbc:mysql://192.168.88.80:3306/teach?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true' \
--username root \
--password 123456 \
--query "select id,class_id,morning_template_id,morning_begin_time,morning_end_time,afternoon_template_id, \
afternoon_begin_time,afternoon_end_time,evening_template_id,evening_begin_time,evening_end_time, \
use_begin_date,use_end_date,create_time,create_person,remark,substr(create_time,1,10) as dt \
 from tbh_class_time_table where 1=1 and  \$CONDITIONS" \
--hcatalog-database edu_ods \
--hcatalog-table tbh_class_time_table \
--split-by id \
-m 2

wait
start_time=`date +"%Y-%m-%d %H:%M:%S"`
echo ""
echo "sqoop tbh_class_time_table end ${start_time}" >> ./sqoop_liujie.log
echo "sqoop tbh_student_signin_record start ${start_time}" >> ./sqoop_liujie.log
echo ""

/usr/bin/sqoop import "-Dorg.apache.sqoop.splitter.allow_text_splitter=true" \
--connect 'jdbc:mysql://192.168.88.80:3306/teach?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true' \
--username root \
--password 123456 \
--query "select id,normal_class_flag,time_table_id,class_id,student_id, \
signin_time,inner_flag,signin_type,share_state,inner_ip,signin_date \
 from tbh_student_signin_record where 1=1 and  \$CONDITIONS" \
--hcatalog-database edu_ods \
--hcatalog-table tbh_student_signin_record \
--split-by id \
-m 2

start_time=`date +"%Y-%m-%d %H:%M:%S"`
echo "sqoop tbh_student_signin_record end ${start_time}" >> ./sqoop_liujie.log








